﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zyan.Communication;
using Zyan.Communication.Protocols;
using Zyan.Communication.Protocols.Tcp;

namespace ES.Shared.Hosting
{
    public class ComponentHost : IDisposable    
    {
        private ZyanComponentHost _host;
        
        public ComponentHost(ComponentHostConfig config)
        {
            if (config==null)
                throw new ArgumentNullException("config");

            TcpCustomServerProtocolSetup protocol=new TcpCustomServerProtocolSetup(config.TcpPort,null,true,"3DES",true);
            _host = new ZyanComponentHost(config.ApplicationName, protocol);
        }

        private bool _disposing = false;

        public void Dispose()
        {
            if (_disposing)
                return;

            _disposing = true;

            if (_host != null)
            {
                _host.Dispose();
                _host = null;
            }
        }
    }
}
